package cn.t16.ms.product;

import cn.t16.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProductController {
    @Resource
    private ProductService productService;

    @GetMapping("/products/{id}")
    public Result get(@PathVariable Integer id) {
        Product product = productService.get(id);
        return Result.returnResult(200,"ok",product);
    }

    @PostMapping("/products")
    public Result save(@RequestBody Product product) {
        productService.save(product);
        return Result.returnResult(200,"ok",product);
    }

    @GetMapping("/products")
    public Result getAll() {
        List<Product> list =  productService.getAll();
        return Result.returnResult(200,"ok",list);
    }


}
